<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
       /* 1.使用Object创建通用对象 */ 
       var user = new Object();
       user.name = "吕布";
       user.age = 18;
       user.say = function(){
           console.log("大家好，我是"+ this.name +",今年"+ this.age +"岁了!");
       }
       user.say();

       var dog = new Object();
       dog.nickdog = "我要吃肉骨头！";
       dog.wag = function(){
           console.log("不然我要拆家了...");
       }
       dog.wag();

       /* 2.使用构造函数 */
       function userinfo(name,age){
           this.name = name;
           this.age = age;
           this.say = function(){
                console.log("大家好，我是"+ this.name +",今年"+ this.age +"岁了!");
           }
       }
       var user = new userinfo("詹姆斯",23);
       user.say();

       /* 3.使用直接量 */
       var user = {
           username: "孙悟空",
           age: 1000,
           say: function(){
                console.log("大家好，我是"+ this.username +",今年"+ this.age +"岁了!");
           }
       };
       user.say();

    </script>
</body>
</html>